package validate;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;

import pojo.RegisterBean;

public class LoginValidate {
	
	@Autowired
	SessionFactory sessionFactory;
	//HibernateTemplate template;
	
	/*public void setTemplate(HibernateTemplate template) {
		this.template = template;
		
	}*/
	
	
	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	
	
	
	
	public String authenticateParentsLogin(String email, String pwd) {
		System.out.println("LoginValidate.authenticateParentsLogin()");
		/*RegisterBean registerObj = (RegisterBean) template.get(
				RegisterBean.class, email);*/
		
		RegisterBean registerObj=(RegisterBean) sessionFactory.getCurrentSession().get(RegisterBean.class, email);
		
		
		
		
		System.out.println("bean get...");
		if (registerObj != null) {
			if ((email.equalsIgnoreCase(registerObj.getEmail()))
					&& (pwd.equals(registerObj.getPwd()))) {

				System.out.println("E-mail :" + registerObj.getEmail());
				System.out.println("Password :" + registerObj.getPwd());
				
				return registerObj.getName();
			}
		}
		return null;
	}

	

	
	/**
	 * Authenticate Admin Login
	 * 
	 */
	/*public String authenticateAdminLogin(String email,String pwd){
		
		System.out.println("LoginValidate.authenticateAdminLogin()");
		
		//Accessing database..
		AdminLoginBean adminbean=template.get(AdminLoginBean.class, email);
		if(adminbean!=null){
			
			if((adminbean.getEmail().equals(email))&&(adminbean.getPwd().equals(pwd))){
				return adminbean.getName();
			}
		}
		return null;
		
	}*/

}
